<%--
  Created by IntelliJ IDEA.
  User: Oleksandr_Terekh
  Date: 9/19/2014
  Time: 12:42 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

<%@ page import="org.simplecrm.domain.event.EventStatus" %>

<%@ include file="../urls.jsp" %>

<c:set var="lang" value="${pageContext.response.locale}"/>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link rel="stylesheet" type="text/css" href="${customersViewStyleUrl}"/>
    <script type="text/javascript" src="${jQueryUrl}"></script>

    <title><spring:message code="title.custView"/></title>
</head>
<body>

<%@ include file="../header.jsp" %>

<h1 style="text-align: center;"><spring:message code="events.EditCaption"/></h1>

<form:form commandName="eventToUpdate" action="${updateEventUrl}">
    <sec:authorize access="hasRole('Support')">
        <c:set var="disabled" value="true"/>
    </sec:authorize>
    <table style="border-color: #666666; border: 1; width: 100%;">
        <tr>
            <td class="eventCell" id="ce1">
                <form:input path="id" type="hidden" value="${eventToUpdate.id}"/>
                <form:input path="customer" type="hidden" value="${eventToUpdate.customer.id}"/>

                <c:if test="${disabled}">
                    <input type="text" value="${eventToUpdate.type.name}"
                           style="width: 100%" disabled/>
                    <form:input path="type" value="${eventToUpdate.type.id}" type="hidden"/>
                </c:if>
                <c:if test="${not disabled}">
                    <form:select path="type" cssStyle="width: 100%">
                        <form:options items="${sessionScope.eventTypes}" itemValue="id" itemLabel="name"/>
                    </form:select>
                </c:if>
                <br/>
                <form:errors path="type" cssClass="error"/>
            </td>
            <td class="eventCell" id="ce2">
                <form:input path="description" value="${eventToUpdate.description}" cssStyle="width: 100%"
                            readonly="${disabled}"/>
                <br/>
                <form:errors path="description" cssClass="error"/>
            </td>
            <td class="eventCell" id="ce3">
                <form:input path="creationDate" value="${eventToUpdate.creationDate}"
                            cssStyle="width: 100%" disabled="true"/>
            </td>
            <td class="eventCell" id="ce4">
                <form:select path="status" cssStyle="width: 100%">
                    <form:options items="<%=EventStatus.values()%>"/>
                </form:select>
                <br/>
                <form:errors path="status" cssClass="error"/>
            </td>
            <td class="eventCell" id="ce5">
                <c:choose>
                    <c:when test="${displayManagerContext && eventToUpdate.status eq 'Planned'}">
                        <form:select path="support" cssStyle="width: 100%">
                            <form:option value="" label="NONE" selected="true"/>
                            <form:options items="${sessionScope.supportList}" itemValue="id" itemLabel="login"/>
                        </form:select>
                    </c:when>
                    <c:otherwise>
                        <input type="text" class="eventEdit"
                               value="${eventToUpdate.support.login==null?MSG_NONE:eventToUpdate.support.login}"
                               style="width: 100%" disabled/>
                        <form:input path="support" value="${eventToUpdate.support.id}" type="hidden"/>
                    </c:otherwise>
                </c:choose>
            </td>
        </tr>
        <tr>
            <td colspan="4"></td>
            <td>
                <input type="submit" value="<spring:message code='events.update'/>"
                       style="width:49%;height:20px;">
                <input type="button" value="<spring:message code='events.cancle'/>"
                       onclick="window.location.href = '${customersUrl}/1'"
                       style="width:49%;height:20px;">
            </td>
        </tr>
    </table>
</form:form>

</body>
</html>
